#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "Includes/Gal.h"
#include <unistd.h>
#include <errno.h>
#include <dlfcn.h>
#include <fcntl.h>

/// <summary>
/// Locals
/// </summary>
static Driver drv =
{
	.state = 0,
	.name = "Empty",
	.Open = NULL,
	.CreateCursor = NULL,
	.ShowCursor = NULL,
	.HideCursor = NULL,
};

/// <summary>
/// TODO
/// </summary>
int GalDriverProbe(void)
{
	return 0;
}

/// <summary>
/// TODO
/// </summary>
int GalLoadDriver(const char *name)
{
	if (!name)
		return -1;

	void *handle = NULL;
	void *driver_init = NULL;

	if (!(handle = dlopen(name, RTLD_LAZY)))
		return -2;

	if (!(driver_init = dlsym(handle, "_DriverInit")))
		return -3;

	if (((DriverInit)driver_init)(&drv) < 0)
		return -4;

	return 0;
}

/// <summary>
/// TODO
/// </summary>
int GalDriverUnload(void)
{
	return 0;
}

/// <summary>
/// TODO
/// </summary>
DriverPtr GalDriver(void)
{
	return &drv;
}
